<?php
class dba{
   const name = 'root';
   const HOST = 'localhost';
    public function __construct(){
        $this->conn = new PDO('mysql:host=localhost;dbname=php',dba::name,dba::name);
        $this->conn->exec("SET NAMES UTF8");
        echo dba::name.'==============';
    }
    
    public function query($sql){
         return $this->conn->query($sql);
    }
}

$con = new dba();
//$sql = "insert into user(username,password) values('卡看看书卡','qqqqq')";

$sql = "select * from user";
$res = $con->query($sql);

while($row = $res->fetch(PDO::FETCH_OBJ)){
    $rows[] = $row;
}

print_r($rows);

echo $rows[1]->username;
echo count($rows);

?>
